<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>焦点事件</title>
    <script>
        window.onload=function(e){
            var username=document.getElementsByClassName('username')[0];
            username.onfocus=function(e){

            }
            username.onblur=function(e){
                if(username.value.length!=4){
                    alert('用户名必须是4个字符')
                }
                
            }
        }
    </script>
    </head>
    <body>
        <div class="messge"></div>
        <div class="login">
                <label for="">用户名：</label> <input type="text" class="username"><br/>
                <label for="">密码：</label> <input type="text" class="password"><br/>
                <input type="button" class="btn-login" value="登录">    
        </div>
    </body>
    </html>